<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>顾客投诉管理</el-breadcrumb-item>
    </el-breadcrumb>
    <!--列表-->
    <el-table size="small" :data="complainList" highlight-current-row v-loading="loading" border element-loading-text="拼命加载中">
      <el-table-column align="center" prop="id" label="投诉编号" width="100">
      </el-table-column>
      <el-table-column align="center" prop="userNickName" label="投诉人" width="100">
      </el-table-column>
      <el-table-column align="center" prop="content" label="投诉内容" width="200"></el-table-column>
      <!-- <el-table-column align="center" prop="createTime" label="投诉时间" width="200"></el-table-column> -->
      <el-table-column align="center" prop="orders.deliverySiteName" label="就餐列车" width="100"></el-table-column>
      <el-table-column align="center" prop="answer" label="是否回复" width="150">
        <template slot-scope="scope">
          {{ scope.row.answer ? '已回复' : '未回复' }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作" width="200">
        <template slot-scope="scope">
            <el-button v-if="!scope.row.answer" size="mini" type="warning" @click="answerComplain(scope.row)">回复</el-button>
          <el-button size="mini" type="danger" @click="deleteComplain(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <Pagination v-bind:child-msg="pageQuery" @callFather="callFather"></Pagination>
    <el-dialog title="回复投诉" :visible.sync="complainDialog" width="40%" @click="closeDialog">
      <el-form label-width="120px">
        <el-form-item label="回复内容">
          <el-input size="small" v-model="form.answer" auto-complete="off" placeholder="请输入回复内容"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="closeDialog">取消</el-button>
        <el-button size="small" type="primary" class="title" @click="answer">回复</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import Pagination from '../../components/Pagination'
export default {
  name:'Complain',
  data() {
    return {
      complainList: [], //用户列表
      pageQuery: {
        pageNum: 1,
        pageSize: -1
      },
      form: {
        id: '',
        answer: ''
      },
      complainDialog: false,
      loading: false //是显示加载
    }
  },
  // 注册组件
  components: {
    Pagination
  },
  created() {
    this.getComplainList(this.pageQuery)
  },
  methods: {
    /**
     * 获取用户列表
     */
    getComplainList(pageQuery) {
      this.loading = true
      this.$api.auth.getComplainList(pageQuery).then(res => {
        if (res.code === 200) {
          this.complainList = res.data.records
          this.loading = false
        }
      }).catch(err => this.loading = false)
    },
    /**
     * 分页插件事件
     */
    callFather(parm) {
      this.pageQuery.pageNum = parm.currentPage
      this.pageQuery.pageSize = parm.pageSize
      this.getComplainList(this.pageQuery)
    },
    closeDialog () {
        this.complainDialog = false
        this.form.answer = ''
    },
    /**
     * 回复 api
     */
    answer () {
        this.$api.auth.answerComplain(this.form).then(res => {
            if (res.code === 200) {
                this.closeDialog()
                this.getComplainList(this.pageQuery)
            }
        })
    },
    /**
     * 回复投诉
     */
    answerComplain (complain) {
        this.complainDialog = true
        this.form.id = complain.id
    },
    /**
     * 删除投诉
     */
    deleteComplain (complain) {
      let query = {
        id: complain.id
      }
      this.$api.auth.deleteComplain(query).then(res => {
        if (res.code === 200) {
          this.getComplainList(this.pageQuery)
        }
      })
    }
  }
}
</script>

<style>
.complain-search {
  margin-top: 20px;
}
.complainRole {
  width: 100%;
}
  .avatar-uploader .el-upload {
    bcomplain: 1px dashed #d9d9d9;
    bcomplain-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    bcomplain-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
</style>

 
 